package org.zhadoop.stream.cql.semanticanalyzer.parser.context;

import java.util.List;

import org.zhadoop.stream.cql.exception.SemanticAnalyzerException;
import org.zhadoop.stream.cql.semanticanalyzer.analyzecontext.expressiondesc.ExpressionDescribe;
import org.zhadoop.stream.cql.semanticanalyzer.parsecontextreplacer.ParseContextReplacer;
import org.zhadoop.stream.cql.semanticanalyzer.parsecontextwalker.ParseContextWalker;

import com.google.common.collect.Lists;

/**
 * case 表达式解析内容
 * 
 * @author zwd
 *
 */
public class CaseExpressionContext extends BaseExpressionParseContext {

	private BaseExpressionParseContext head;

	// CaseWhenBodyWhenBodyContext
	private List<BaseExpressionParseContext> whens;

	// CaseWhenBodyThenBodyContext
	private List<BaseExpressionParseContext> thens;

	private BaseExpressionParseContext caseWhenElse;

	public CaseExpressionContext() {
		whens = Lists.newArrayList();
		thens = Lists.newArrayList();
	}

	@Override
	public void walkChildAndReplace(ParseContextReplacer replacer) {
		// TODO Auto-generated method stub

	}

	@Override
	protected ExpressionDescribe createExpressionDesc() throws SemanticAnalyzerException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("CASE ");
		sb.append(head.toString() + " ");

		for (int i = 0; i < whens.size(); i++) {
			sb.append(whens.get(i).toString());
			sb.append(" ");
			sb.append(thens.get(i).toString());
			sb.append(" ");
		}

		if (caseWhenElse != null) {
			sb.append(" " + caseWhenElse.toString());
		}
		sb.append(" END ");
		return sb.toString();
	}

	@Override
	protected void walkChild(ParseContextWalker walker) {
		// TODO Auto-generated method stub

	}

	public BaseExpressionParseContext getHead() {
		return head;
	}

	public void setHead(BaseExpressionParseContext head) {
		this.head = head;
	}

	public List<BaseExpressionParseContext> getWhens() {
		return whens;
	}

	public void setWhens(List<BaseExpressionParseContext> whens) {
		this.whens = whens;
	}

	public List<BaseExpressionParseContext> getThens() {
		return thens;
	}

	public void setThens(List<BaseExpressionParseContext> thens) {
		this.thens = thens;
	}

	public BaseExpressionParseContext getCaseWhenElse() {
		return caseWhenElse;
	}

	public void setCaseWhenElse(BaseExpressionParseContext caseWhenElse) {
		this.caseWhenElse = caseWhenElse;
	}
	
	

}
